An instance draws its own sprite automatically until you write a Draw event, and after that you must call draw_self() yourself or it disappears.
If you add a Draw event to an object and do not call draw_self() in it, that object's sprite stops appearing on screen. Nothing is broken. The game is doing what a Draw event means: you have taken over the drawing of that object.
Drawing calls only work in the drawing events. Every draw_ call (draw_self, draw_sprite, draw_text, draw_rect_fill, draw_background and the rest) is allowed in a Draw, Draw Begin, Draw End or Draw GUI event, and the checker refuses one anywhere else (a Step event, a Create event) and tells you to move it. A script may draw: it takes the event of whoever calls it.
| The object has | What you see |
|---|---|
| no Draw event | its sprite, drawn for you every frame |
a Draw event with draw_self(); in it | its sprite, plus whatever else you draw in the event |
a Draw event without draw_self(); | nothing from its own sprite. Only what your code draws |
The fix is one line, put first in the event:
// Draw event of an enemy that has noticed the player
draw_self();
draw_text(x, y - 20, "!");draw_self() draws the instance exactly the way automatic drawing would. Everything after it is extra: a label, a glow, a held item.
Some details, because this is the most common way to think the tool has stopped working:
draw_self(). It is only a hint, because an object that draws nothing of its own is sometimes exactly what you want.visible is false. draw_self() does not check visible. Inside a Draw event, write if (visible) { draw_self(); } if you still want visible to work.The GBA draws two kinds of thing: sprites and backgrounds. This page is about sprites - the pictures that belong to instances. A sprite is a small image, and one instance normally shows one. Backgrounds covers the other kind. The screen is 240 pixels wide and 160 tall. The hardware draws at most 128 sprites in one frame, so every sprite you show spends from a fixed budget. Budgets lists it.
Without a Draw event, the engine draws each instance from its own variables:
| Variable | What it does |
|---|---|
sprite | which sprite to show. Leave it unset to draw nothing |
frame | which picture of a multi-picture sprite (an animation frame) to show |
frame_count | how many pictures the sprite has. Read-only |
frame_speed | how many animation frames frame moves forward every game frame. 0 (the default) means no animation, 1 changes the picture 60 times a second, 0.5 changes it every other game frame, 0.125 every eighth. Wraps back to the first picture by itself |
angle | rotation in degrees |
xscale, yscale | stretch. 1 is normal size, and a negative value mirrors |
flip_x, flip_y | mirror left-right or top-bottom |
visible | false hides it |
depth, bg_priority | what draws in front of what. See below |
Rotating or stretching a sprite uses one of the hardware's 32 affine matrices, the small calculators that do the turning, for as long as the sprite is on screen. A plain mirror does not use one. Leave angle at 0 and the scales at 1 on anything that never needs them. Automatic drawing also skips an instance the camera cannot currently see.
Where the sprite appears is the instance's x and y (counted from the room's top-left corner, see Where (0, 0) is), at the sprite's origin. The origin is the spot on the picture that sits exactly at the object's position. It is the center unless the sprite was given a different origin in the Sprites tab.
An object can also choose its own origin: in the object editor, press Set Origin next to the collision mask, then click the picture, type an X and Y, or press Origin Center. It counts in pixels from the top-left corner of one frame and is the same on every frame. The object's own choice wins over the sprite's, but only for that object's own drawing (default drawing and draw_self); draw_sprite draws a sprite you name, so it still uses that sprite's origin. The collision box stays on the picture when you move the origin, so the two never drift apart.
A rectangle is different, because it has no picture and so no origin to pick. draw_rect_fill, draw_rect, and their _anchored forms put the rectangle's top-left corner at the (x, y) you give. So draw_rect_fill(0, 0, screen_width(), screen_height(), COLOR_BLUE) fills the whole screen.
This one catches people, so it is worth knowing before it wastes your afternoon.
Moving the origin changes which spot on the picture sits at the object's position. It does not, on its own, decide where the picture ends up on screen - because something else may be deciding the position.
Say a player falls until it lands on the ground. The collision box stays on the picture (above), so the player stops falling when its art touches the ground, whatever the origin is. Move the origin down by 6 pixels and the player simply rests at a position 6 pixels lower - and lands in exactly the same place on screen. Nothing looks different, and nothing is wrong.
You can see the origin working in the frames before it lands. It really is drawn 6 pixels higher while falling; it is only once the ground decides its position that the difference disappears.
So to see what an origin does, try it on something whose position you control: an object that just sits there, a sprite you place by hand, or your falling player before it touches the ground. Then the picture moves exactly as much as you moved the origin.
And that is the useful way to think about it. The origin is about the point you hold the object by - which matters enormously for rotation, for lining a character up with a tile, and for saying "put its feet here" instead of "put its middle here". It is not a way to nudge a picture around.
Once you write a Draw event, you make the drawing calls. Three events draw in world space, meaning they scroll with the camera, and three more draw fixed to the screen. The drawing calls are the same in both: it is the event that decides where a call draws.
| Event | Space | Runs |
|---|---|---|
| Draw Begin | world | first |
| Draw | world | then this. The one that turns automatic drawing off |
| Draw End | world | then this |
| Draw GUI Begin, Draw GUI, Draw GUI End | screen | after the world events, in that order |
The GUI events are for anything that stays put while the room scrolls: a health bar, a score. They draw on a layer of their own: (0, 0) is the top-left pixel of the screen there, and everything drawn in them sits on top of the whole game. See Draw GUI. An event running earlier is not the same as drawing behind. What sits in front is decided by the order rules below.
The drawing calls:
| Call | Draws |
|---|---|
draw_self() | this instance, the automatic way |
draw_sprite(spr, x, y, frame) | any sprite, anywhere, at this instance's own depth |
draw_sprite_scaled(...) | the same with angle, scale, flips and its own depth |
draw_rect_fill | a filled rectangle, in one of eight COLOR_ constants |
draw_rect | a one-pixel outline |
draw_text and its kin | text. See Text |
show_collision(on), show_collision_all(on) | a red outline of the collision box, for debugging |
The GBA has no canvas to paint on. Each call above makes a real sprite. draw_rect_fill is one sprite, stretched to the size you asked for. An outline is up to four sprites, one per side. The engine remembers each call from one frame to the next. A call that draws the same thing every frame reuses last frame's sprite, and a call you stop making has its sprite released at the end of that frame. A Draw event that changes every frame costs a real sprite for the change.
Five functions ask about a sprite asset without drawing anything: sprite_width, sprite_height and sprite_frames, plus sprite_origin_x and sprite_origin_y for where its origin is.
Two settings decide this, and the first beats the second.
bg_priority picks one of four hardware layers, from 0 (nearest the viewer) to 3 (furthest back). The default is 3. A sprite draws in front of a background on its own layer or a layer behind it. It draws behind a background on a layer in front. A tie goes to the sprite.depth orders sprites against each other on one layer. A higher depth draws further back. The classic top-down use is depth = -y;, so whatever is lower on the screen draws in front.A third rule applies inside one Draw event that draws a background with draw_background: sprites and backgrounds stack in the order you make the calls, and what you draw later is in front. Draw a sprite and then a big solid background and the sprite is hidden. draw_background says how many switches between sprites and backgrounds fit.
Two things catch people out. depth is grouped into a small number of bands, because the hardware has a limited number of sort layers. Two instances with nearly the same depth land in the same band and draw in the order they were created. And everything drawn in a Draw GUI event is on the front-most layer, so nothing in the world can cover it. Where the machine shows through explains the bands.
Motion and pathing moves the instance that is being drawn. Text, Backgrounds, The camera and Effects cover the rest of what the screen shows.